<?php
class TesterController extends Controller
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	public $layout='//layouts/blog';

	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
		);
	}

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
				'actions'=>array('index','view','list','rss','search','test','testatr','testEvent','testBehavior','visitorinfo'),
				'users'=>array('*'),
			),
			array('allow', // allow authenticated user to perform 'create' and 'update' actions
				'actions'=>array('create','update'),
				'users'=>array('@'),
			),
			array('allow', // allow admin user to perform 'admin' and 'delete' actions
				'actions'=>array('admin','delete'),
				'users'=>array('admin'),
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}
    
    public function actionIndex(){
        
        $this->layout = 'layouts/blank';
        
  		$geoIp = new EGeoIP();
		 
		$geoIp->locate('110.186.226.156'); // use your IP
        
        $this->render('index',array(
            'latitude'=>$geoIp->latitude,
            'longitude'=>$geoIp->longitude
        ));
        
    }
    
    public function actionBaiduMap()
    {
  		Yii::import('application.helpers.EGeoIP');
 
		$geoIp = new EGeoIP();
		 
		$geoIp->locate('110.186.226.156'); // use your IP
		 
		echo 'Information regarding IP: <b>'.$geoIp->ip.'</b><br/>';
		echo 'City: '.$geoIp->city.'<br>';
		echo 'Region: '.$geoIp->region.'<br>';
		echo 'Area Code: '.$geoIp->areaCode.'<br>';
		echo 'DMA: '.$geoIp->dma.'<br>';
		echo 'Country Code: '.$geoIp->countryCode.'<br>';
		echo 'Country Name: '.$geoIp->countryName.'<br>';
		echo 'Continent Code: '.$geoIp->continentCode.'<br>';
		echo 'Latitude: '.$geoIp->latitude.'<br>';
		echo 'Longitude: '.$geoIp->longitude.'<br>';
		echo 'Currency Symbol: '.$geoIp->currencySymbol.'<br>';
		echo 'Currency Code: '.$geoIp->currencyCode.'<br>';
		echo 'Currency Converter: '.$geoIp->currencyConverter.'<br/>';
		 
		echo 'Converting $10.00 to '.$geoIp->currencyCode.': <b>'.$geoIp->currencyConvert(10).'</b><br/>';
    }
	
	public function actionTest()
	{		
		$this->render('test');
	}
	
    public function actionFlash()
    {
  	
        
        if(isset($_POST['name'])){
        	
        	$str = '完全';
        	
            Yii::app()->user->setFlash('power',$str);
            $this->refresh();
        }
        
        $this->render('flash');
        
    }
    public function actionCache()
    {
        $content = $_GET;
        
        $id = 'testcache';
        
        $data = Yii::app()->fileCache->get($id);
        
        if($data === false)
        {
            $data = $_GET;
            
            Yii::app()->fileCache->set($id,$data, 660, new CFileCacheDependency('./public/log.txt'));
        }
        
        UtilHelper::dump($data);
    }
    
	public function actionFilepath()
	{
     
		$model = File::model()->find(array(
					'condition'=>'file_id = 49',
					'order'=>'file_id DESC'
				));
		
// 		UtilHelper::dump($model->attributes);
		
// 		die();
		
//		$source = File::model()->generateFilePath($model, true, false);
//		//$destination = File::model()->generateFilePath($model,false, true);
//        $destination = File::model()->generateOriginFilePath($model, true, true, '/public/dkd/');
//        
//        
//        File::model()->getPerfectImage($source, $destination, 200, 2000, false);
        
        echo File::model()->generateOriginFilePath($model, false,true);
        echo "<br />";
        echo File::model()->generateFilePath($model, false, true);
        
        
        
        
        echo filectime($source);
        
        echo '<br />';
        
        echo $source.'<br />'.$destination;

die();
	
		$width = 210;

		try {
			
			$t = new ThumbHandler();
			$t->setSrcImg($source);
			$t->setImgDisplayQuality(90);
			$t->setCutType(1);//指明为手工裁切
			$t->setDstImg($destination);
            
            $t->setMaskImg('./public/images/logo.png');
            $t->setMaskPosition(4);

			
			$w = $t->getSrcImgWidth();
			$h = $t->getSrcImgHeight();
			
			//宽度缩放比例
			$percent = floatval($width/$w)*100;
//			echo $w. '-'. $h.'-';
//			echo $percent;
//			die();
			
			$t->createImg($percent);
			
		}catch(CException $e){
			echo $e->getTraceAsString();
		}
        
        echo CHtml::image($destination);

		

		
	}
	
	function test(&$value, $key, $prefix='file')
	{
		$value =  $prefix.$value;
	}
	
	public function actionKeyExchange()
	{
		


		$result =array(
				
				'name'=>'AronJhon',
				'password'=>'Aaronpassword'
				
				);
		
		$keys = array_keys($result);
		
		array_walk($keys, 'TesterController::test', 'file_');
		
		$values = array_values($result);
		
		$result['key']=$keys;
		$result['value']=$value;
		
		$result = array_combine($keys, $values);
		
		UtilHelper::dump($result);

	}


	
	public function actionVisitorInfo()
	{
		
		Yii::import('application.components.visitors.QQWry');
		
		$ipp = '182.128.111.224';
		
		$qq = new QQWry($ipp);
		
		UtilTools::dump($qq);
		
		$str = $qq->getDetailInfo();
		
// 		echo Visitors::model()->getVisitorHead($ipp,$str);
		
// 		Yii::app()->end();
	}
	
	public function actionTestAtr(){  
        $com = new testComponent();  
        $com -> atr = "atr";  
        echo $com -> atr;  
    }  
    public function actionTestEvent(){  
        $com = new TestComponent();  
//        $com -> testEvent(); 
        $com -> clickedEvent();
    }  
    public function actionTestBehavior(){  
        $com = new TestComponent();  
        $com -> testBehavior();  
    }  
}
